Imports DAL
Imports System.Windows.Forms
Imports System.Configuration
Imports System.IO
Imports System.Drawing
Imports System.Text
Imports MyClasses
Imports System.Windows.Forms.ToolTip
Imports System.ComponentModel
Imports System.Data.SqlClient

Public Class BCommon
    Public Enum GroupTypes
        UNIT = 1
        PRODUCT = 2
        SUPPLIER = 3
        PARTY = 4
        USER = 5
    End Enum

    Public Shared Sub ErrorHandler(ByVal ErrDescr As String, ByVal ProjectName As String, ByVal FormName As String, ByVal FuncOrSubName As String, Optional ByVal strSql As String = "")
        DGeneral.ErrorHandler(ErrDescr, ProjectName, FormName, FuncOrSubName, strSql)
    End Sub
    Public Shared Sub ErrorHandler(ByVal ErrDescr As String)
        DGeneral.ErrorHandler(ErrDescr, "", "", "", "")
    End Sub
    Public Shared Sub AssignToolTips(ByRef Form As Form)

    End Sub

    Public Shared Sub SetDatePickerMaxMinDate(ByRef dtpckr As DateTimePicker)
        Dim dtDatePkr As New DataTable
        Try
            If ConfigurationManager.AppSettings("FormMode") <> "R" Then
                dtDatePkr = BCommon.GetDatePicker()
                If dtDatePkr.Rows.Count > 0 Then
                    dtpckr.MinDate = dtDatePkr.Rows(0).Item("fin_start_dt")
                    dtpckr.MaxDate = dtDatePkr.Rows(0).Item("fin_end_dt")
                End If
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetDatePickerMaxMinDate")
        End Try
    End Sub

    'ADDED BY  O$-DEC-2005
    Public Shared Sub SetFormStandards(ByRef Form As Form, Optional ByVal SetReadOnly As Boolean = True)
        Dim ctrl As Control

        Dim ctrlarr() As String
        'Form.BackColor = Color.FromArgb(164, 201, 250)
        'Form.BackColor = Color.FromArgb(204, 224, 248)
        Form.BackColor = Color.AliceBlue

        'LABEL SETTING 
        Dim dtsLables As New DataSet
        Dim Fnt As Font = New Font("Verdana", 8, FontStyle.Bold)
        Dim btnFnt As Font = New Font("Verdana", 9, FontStyle.Bold)
        Dim EntFnt As Font = New Font("Verdana", 8, FontStyle.Regular)
        Dim i As Integer = 0
        Dim j As Integer = 0
        Try
            'Form.Icon = Global.BAL.My.Resources.RxOffice1Icon32x32 '  .My.Resources.Resources.uas_search

            dtsLables = DGeneral.GetLabels(Form.Name)

            If IsNothing(dtsLables) Then
                MessageBox.Show("No lables")
                Exit Sub

            End If
            With dtsLables.Tables(0)
                For i = 0 To .Rows.Count - 1
                    If Trim(.Rows(i).Item("Container")) = "" Then

                        'Form.Controls(.Rows(i).Item("ControlName")).Text = CStr(.Rows(i).Item("ControlCaption"))
                        'Form.Controls(.Rows(i).Item("ControlName")).Font = Fnt '"Arial"
                        ctrl = Form.Controls(.Rows(i).Item("ControlName"))

                    Else
                        If Trim(.Rows(i).Item("Container")).IndexOf("|") > 0 Then
                            ctrl = Nothing
                            ctrlarr = Trim(.Rows(i).Item("Container")).Split("|")
                            For j = 0 To UBound(ctrlarr)
                                If j = 0 Then
                                    ctrl = Form.Controls(ctrlarr(j))
                                Else
                                    ctrl = ctrl.Controls(ctrlarr(j))
                                End If
                            Next
                            ctrl = ctrl.Controls(.Rows(i).Item("ControlName"))
                        Else
                            Dim ContainerCntrl As Control = Form.Controls(.Rows(i).Item("Container").ToString())
                            Try


                                ctrl = ContainerCntrl.Controls(.Rows(i).Item("ControlName").ToString())

                            Catch ex As Exception
                                'BCommon.ErrorHandler(ex.Message & Form.Name, "BAL", "BCommon", "SetFormStandards-Label")
                            End Try
                            'Form.Controls(.Rows(i).Item("Container").ToString()).Controls(.Rows(i).Item("ControlName")).Text = CStr(.Rows(i).Item("ControlCaption"))
                            'Form.Controls(.Rows(i).Item("Container").ToString()).Controls(.Rows(i).Item("ControlName")).Font = Fnt ' "Arial"
                        End If

                    End If

                    If ctrl Is Nothing Then
                        'MessageBox.Show("Control=" & .Rows(i).Item("ControlName") & ",Container=" & .Rows(i).Item("Container") & "", Form.Name)
                        'BCommon.ErrorHandler("Control=" & .Rows(i).Item("ControlName") & ",Container=" & .Rows(i).Item("Container") & "", "GUI", "BCommon", "SetFormStandards-Label")
                    Else
                        If ctrl.GetType.Name = "Button" Then
                            ctrl.Text = CStr(.Rows(i).Item("ControlCaption"))
                            ctrl.Font = btnFnt
                            'ctrl.ForeColor = Color.DarkBlue
                            ctrl.ForeColor = Color.FromArgb(4, 55, 102)
                            AddHandler ctrl.MouseMove, AddressOf SetMouseOverColor
                            AddHandler ctrl.MouseLeave, AddressOf SetMouseLeaveColor
                        Else
                            ctrl.Text = CStr(.Rows(i).Item("ControlCaption"))
                            ctrl.Font = Fnt
                            'ctrl.ForeColor = Color.DarkBlue
                            ctrl.ForeColor = Color.FromArgb(64, 64, 64)

                        End If
                    End If

                Next
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message & Form.Name, "BAL", "BCommon", "SetFormStandards-Label")
        End Try
        'SET FONT 
        Try
            For Each ctrl In Form.Controls
                If ctrl.HasChildren Then
                    SetStandardonChildControl(ctrl)
                    ctrl.Font = EntFnt
                    If ctrl.Tag = "BTN" Then
                        'ctrl.BackColor = Color.FromArgb(79, 112, 165)
                        'ctrl.BackColor = Color.FromArgb(13, 104, 159)
                        'ctrl.BackColor = Color.CadetBlue
                        ctrl.BackColor = Color.FromArgb(214, 243, 254)

                    Else
                        ctrl.BackColor = Color.AliceBlue
                    End If
                Else
                    Select Case ctrl.GetType.Name
                        Case "ComboBox"
                            ctrl.Font = EntFnt
                        Case "Button"
                            ctrl.Font = btnFnt
                        Case "Panel"
                            ctrl.Font = EntFnt
                        Case "TextBox"
                            ctrl.Font = EntFnt
                        Case "DateTimePicker"
                            ctrl.Font = EntFnt
                            'IF MODE IS READONLY THEN DONT SET MINDATE ,MAXDATE
                            'FormMode

                            'Case "C1FlexGrid"
                            '    If ctrl.Tag = "" Then
                            '        SetFlexGrid(ctrl)
                            '    End If
                        Case "GroupBox"
                            ctrl.Font = Fnt

                            If ctrl.Tag = "BTN" Then
                                ctrl.BackColor = Color.FromArgb(13, 104, 159)
                            Else
                                ctrl.BackColor = Color.AliceBlue
                            End If

                            'ctrl.BackColor = Color.FromArgb(164, 201, 250)
                            ''ctrl.BackColor = Color.FromArgb(204, 224, 248)
                    End Select
                End If
            Next
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message & Form.Name, "BAL", "BCommon", "SetFormStandards-Tooltip")
        End Try

        ' ADD CODE FOR SET FORM MODE VALUE
        Try
            If SetReadOnly AndAlso ConfigurationManager.AppSettings("FormMode") = "R" Then
                For Each Cntrl As Control In Form.Controls
                    SetControlReadOnly(Cntrl)
                Next
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message & Form.Name, "BAL", "BCommon", "SetFormStandards-SetReadOnly:" & Form.Name)
        End Try
    End Sub
    Public Shared Sub SetStandardonChildControl(ByVal pctrl As Control)
        Dim ctrl As Control
        Dim Fnt As Font = New Font("Verdana", 8, FontStyle.Bold)
        Dim EntFnt As Font = New Font("Verdana", 8, FontStyle.Regular)
        For Each ctrl In pctrl.Controls
            If ctrl.HasChildren Then
                SetStandardonChildControl(ctrl)
                ctrl.Font = EntFnt
                If ctrl.Tag = "BTN" Then
                    'ctrl.BackColor = Color.FromArgb(79, 112, 165)
                    ctrl.BackColor = Color.FromArgb(13, 104, 159)
                Else
                    ctrl.BackColor = Color.AliceBlue
                End If
            Else
                Select Case ctrl.GetType.Name
                    Case "ComboBox"
                        ctrl.Font = EntFnt
                    Case "Button"

                    Case "Panel"
                        ctrl.Font = EntFnt
                    Case "TextBox"
                        ctrl.Font = EntFnt
                    Case "DateTimePicker"
                        ctrl.Font = EntFnt
                        'Case "C1FlexGrid"
                        '    If ctrl.Tag = "" Then
                        '        SetFlexGrid(ctrl)
                        '    End If
                    Case "GroupBox"
                        ctrl.Font = Fnt

                        If ctrl.Tag = "BTN" Then
                            'ctrl.BackColor = Color.FromArgb(79, 112, 165)
                            ctrl.BackColor = Color.FromArgb(13, 104, 159)
                        Else
                            ctrl.BackColor = Color.AliceBlue
                        End If

                        'ctrl.BackColor = Color.FromArgb(164, 201, 250)
                        ''ctrl.BackColor = Color.FromArgb(204, 224, 248)
                End Select
            End If

        Next
    End Sub

    Public Shared Sub SetMouseOverColor(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        sender.BackColor = Color.FromArgb(13, 104, 159)
        sender.ForeColor = Color.White
    End Sub
    Public Shared Sub SetMouseLeaveColor(ByVal sender As Object, ByVal e As System.EventArgs)
        sender.BackColor = Color.AliceBlue
        sender.ForeColor = Color.FromArgb(4, 55, 102)
        'sender.ForeColor = Color.White
    End Sub
    ' @ 15Dec2007
    Public Shared FileExtension As String = "SQLBackup"
    ' @ 15Dec2007
    Public Shared Sub Format_Grid(ByRef dg As DataGridView)
        Dim intCountCol As Integer
        ' Dim i As Integer
        Try
            If Not IsNothing(dg.DataSource) Then
                For intCountCol = 0 To dg.Columns.Count - 1
                    If intCountCol = 0 Then
                        dg.Columns(0).Width = 200
                        dg.Columns(0).ReadOnly = True
                    End If
                    If intCountCol = 1 Then
                        dg.Columns(1).Width = 80
                        dg.Columns(1).ReadOnly = False
                    End If
                    If intCountCol = 2 Then
                        dg.Columns(2).Width = 150
                        dg.Columns(2).ReadOnly = False
                        If dg.Columns(2).Name = "ScriptSQL" Then
                            dg.Columns(2).Visible = False
                        End If
                        If dg.Columns(2).Name = "Status" Then
                            dg.Columns(2).ReadOnly = True
                        End If
                    End If
                    If intCountCol = 3 Then
                        dg.Columns(3).Width = 200
                        dg.Columns(3).ReadOnly = False
                    End If
                    If intCountCol = 4 Then
                        dg.Columns(4).Width = 200
                        dg.Columns(4).ReadOnly = False
                        dg.Columns(4).Visible = False
                    End If
                    If intCountCol = 5 Then
                        dg.Columns(5).Width = 200
                        If dg.Columns(5).Name = "Status" Then
                            dg.Columns(5).ReadOnly = True
                        End If
                    End If
                Next
                dg.RowHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                dg.AllowUserToAddRows = False
                dg.AllowUserToDeleteRows = False
                dg.AllowUserToResizeRows = False
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "AssignLabels")
        End Try
    End Sub
    ' @ 15Dec2007
    Public Shared Function AskDirectory() As String
        Dim folderBrowse As New FolderBrowserDialog
        If folderBrowse.ShowDialog() = DialogResult.OK Then
            Return folderBrowse.SelectedPath
        Else
            Return ""
        End If
    End Function
    ' @ 15Dec2007
    Public Shared Function AskSaveAsFile() As String
        Dim fileD As New SaveFileDialog
        fileD.Filter = "SQLBackup Files | *." + BCommon.FileExtension
        If fileD.ShowDialog() = DialogResult.OK Then
            Return fileD.FileName
        Else
            Return ""
        End If
    End Function
    ' @ 15Dec2007
    Public Shared Function AskOpenFile() As String
        Dim fileD As New OpenFileDialog
        fileD.Filter = "SQLBackup Files | *." + BCommon.FileExtension
        If fileD.ShowDialog() = DialogResult.OK Then
            Return fileD.FileName
        Else
            Return ""
        End If
    End Function

    Public Shared Sub ShowMsgError(ByVal ErrorNumber As Integer)
        Dim dtsError As DataTable

        dtsError = DGeneral.GetError(ErrorNumber)
        'MsdnMag.MessageBox();

        With dtsError
            If .Rows.Count > 0 Then
                If ConfigurationManager.AppSettings("MSGBOX") = "Default" Then       '@25/03/2008 : Condition checked for Customize User Settings
                    Select Case UCase(.Rows(0).Item("Type"))
                        Case "M" 'Messaage
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Case "E" 'Error
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error)
                        Case "I" 'Information
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Case "Q" 'Question
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.Question)
                        Case "W" 'Warning
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.Warning)
                        Case Else
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.None)
                    End Select
                Else                                     '@25/03/2008 : Else part written for Message Box Custom Title
                    Select Case UCase(.Rows(0).Item("Type"))
                        Case "M" 'Messaage
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Case "E" 'Error
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error)
                        Case "I" 'Information
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.OK, MessageBoxIcon.Information)
                        Case "Q" 'Question
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.OK, MessageBoxIcon.Question)
                        Case "W" 'Warning
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.OK, MessageBoxIcon.Warning)
                        Case Else
                            MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.OK, MessageBoxIcon.None)
                    End Select
                End If
            Else
                MessageBox.Show("Message not Found for " & ErrorNumber, "ADD TO DATABASE") ' ConfigurationManager.AppSettings("MsgTitle")
            End If
        End With

    End Sub

    Public Shared Function ShowMsgError(ByVal ErrorNumber As Integer, ByVal MsgboxButtons As String) As Windows.Forms.DialogResult
        Dim dtsError As DataTable
        dtsError = DGeneral.GetError(ErrorNumber)
        With dtsError
            If dtsError.Rows.Count > 0 Then
                If ConfigurationManager.AppSettings("MSGBOX") = "Default" Then          '@25/03/2008 : Condition checked for Customize User Settings
                    Select Case UCase(MsgboxButtons)
                        Case "YN" 'YES NO
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                        Case "YNC" 'YES NO CANCEL
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
                        Case "OC" 'OK CANCEL
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
                        Case "RC" 'RETRY CANCEL
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.RetryCancel, MessageBoxIcon.Question)
                        Case "O" 'OK
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.Question)
                        Case "ARI" 'ABORT RETRY IGNORE
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question)
                    End Select
                Else                                                                    '@25/03/2008 : Else part written for Message Box Custom Title
                    Select Case UCase(MsgboxButtons)
                        Case "YN" 'YES NO
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                        Case "YNC" 'YES NO CANCEL
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
                        Case "OC" 'OK CANCEL
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
                        Case "RC" 'RETRY CANCEL
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.RetryCancel, MessageBoxIcon.Question)
                        Case "O" 'OK
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.OK, MessageBoxIcon.Question)
                        Case "ARI" 'ABORT RETRY IGNORE
                            Return MessageBox.Show(.Rows(0).Item("Message"), ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Question)
                    End Select
                End If
            End If
        End With

    End Function

    Public Shared Sub ShowMessage(ByVal Message As String)
        If ConfigurationManager.AppSettings("MSGBOX") = "Default" Then
            MessageBox.Show(Message, ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        Else
            MessageBox.Show(Message, ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End If
    End Sub

    Public Shared Sub ShowError(ByVal ErrorMessage As String)
        If ConfigurationManager.AppSettings("MSGBOX") = "Default" Then
            MessageBox.Show(ErrorMessage, ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.Information)
        Else
            MessageBox.Show(ErrorMessage, ConfigurationManager.AppSettings("MsgBoxCusTitle"), MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
    End Sub

    Public Shared Sub ShowMsgError(ByVal ErrorNumber As Integer, ByRef OwnerForm As Form)
        Dim dtbError As DataTable
        dtbError = DGeneral.GetError(ErrorNumber)
        With dtbError
            If .Rows.Count > 0 Then
                If .Rows(0).Item("ErrType") = "M" Then
                    MessageBox.Show(OwnerForm, .Rows(0).Item("ErrMessage"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.Information)
                Else
                    MessageBox.Show(OwnerForm, .Rows(0).Item("ErrMessage"), ConfigurationManager.AppSettings("MsgTitle"), MessageBoxButtons.OK, MessageBoxIcon.Error)
                End If
            Else
                MessageBox.Show(OwnerForm, "Message not Found.", ConfigurationManager.AppSettings("MsgTitle"))
            End If
        End With
    End Sub

    Public Shared Function GetMessage(ByVal MessageNo As Integer) As String

        Dim dtbError As DataTable
        dtbError = DGeneral.GetError(MessageNo)

        With dtbError
            If .Rows.Count > 0 Then : Return .Rows(0).Item("Message")
            Else : Return "Message not Found."
            End If
        End With

    End Function
    '>>   19/10/2007
    Public Shared Function GetTitle() As DataTable
        Dim dtTiitle As DataTable
        dtTiitle = DGeneral.GetTitle()
        Return dtTiitle
    End Function

    Public Shared Function GetPrefValue(ByVal PrefName As String) As String
        Return DGeneral.GetPrefVal(PrefName)
    End Function
    Public Shared Function GetLocation() As DataTable
        Return DGeneral.GetLocation()
    End Function

    Public Shared Sub SetComboValues(ByRef cmbbox As ComboBox, ByVal CodeType As String, Optional ByVal AddBlank As Boolean = False, Optional ByVal OrderByIDorDesc As Char = "D")
        'I -> ID
        'D -> Descreption
        Dim dtsCommon As DataTable

        Try
            If AddBlank = True Then
                dtsCommon = DMiscCode.GetCodesWithBlank(CodeType, OrderByIDorDesc)
            Else
                dtsCommon = DMiscCode.GetCodes(CodeType, OrderByIDorDesc)
            End If
            cmbbox.DataSource = dtsCommon
            cmbbox.ValueMember = dtsCommon.Columns("CodeID").ToString()
            cmbbox.DisplayMember = dtsCommon.Columns("CodeDesc").ToString()

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetComboValues")
        End Try

    End Sub


    Public Shared Function SetListValues(ByRef lstbox As CheckedListBox, ByVal CodeType As String, Optional ByVal AddBlank As Boolean = False, Optional ByVal OrderByIDorDesc As Char = "D") As DataTable
        'I -> ID
        'D -> Descreption
        Dim dtsCommon As New DataTable
        Try

            If AddBlank = True Then
                dtsCommon = DMiscCode.GetCodesWithBlank(CodeType, OrderByIDorDesc)
            Else
                dtsCommon = DMiscCode.GetCodes(CodeType, OrderByIDorDesc)
            End If

            lstbox.DataSource = dtsCommon
            lstbox.ValueMember = dtsCommon.Columns("CodeID").ToString()
            lstbox.DisplayMember = dtsCommon.Columns("CodeDesc").ToString()

            Return dtsCommon
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetListValues")
            Return Nothing
        End Try

    End Function
    ' 23/10/2007
    Public Shared Function GetNameSeq() As DataTable
        Dim dtNmSeq As DataTable
        dtNmSeq = DGeneral.GetNameSeq()
        Return dtNmSeq
    End Function


    Public Shared Sub SetComboValues(ByRef cmbbox As ComboBox, ByVal dttable As DataTable, ByVal ValueMember As String, ByVal DispMember As String)
        Try


            cmbbox.DataSource = dttable
            cmbbox.ValueMember = dttable.Columns(ValueMember).ToString()
            cmbbox.DisplayMember = dttable.Columns(DispMember).ToString()

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetComboValues")
        End Try
    End Sub

    'Public Shared Sub SetComboValues(ByRef cmbbox As ComboBox, ByVal ValueMember As String, ByVal DispMember As String)
    '    Try

    '        'Dim dttable As New DataTable
    '        'dttable.Load(DSaleReturn.GetItem(0, False))


    '        cmbbox.DataSource = DSaleReturn.GetItem(0, False)
    '        cmbbox.ValueMember = cmbbox.DataSource.Columns(ValueMember).ToString()
    '        cmbbox.DisplayMember = cmbbox.DataSource.Columns(DispMember).ToString()

    '    Catch ex As Exception
    '        BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetComboValues")
    '    End Try
    'End Sub


    'Public Shared Sub SetComboValues(ByRef cmbbox As ComboBox, ByVal LoadWhat As String)
    '    Dim strSql As String
    '    Try
    '        Select Case LoadWhat
    '            Case "ITEM"
    '                strSql = ""

    '            Case ""
    '                strSql = ""
    '        End Select

    '        If Trim(strSql) = "" Then Exit Sub
    '        Dim ComboReader As SqlDataReader
    '        ComboReader = DbHelper.ExecuteDataReader(strSql)
    '        'cmbbox.DataSource
    '        'cmbbox.ValueMember = "ABC" 'dttable.Columns(0).ToString()
    '        'cmbbox.DisplayMember = "XYA" ' dttable.Columns(DispMember).ToString()

    '    Catch ex As Exception
    '        BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetComboValues")
    '    End Try
    'End Sub


    Public Shared Sub SetComboValWithIndex(ByRef cmbbox As ComboBox, ByVal dttable As DataTable)
        Try
            cmbbox.DataSource = dttable
            If Not IsNothing(dttable) Then
                If dttable.Rows.Count > 0 Then
                    cmbbox.ValueMember = dttable.Columns(0).ToString()
                    cmbbox.DisplayMember = dttable.Columns(1).ToString()
                End If
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetComboValWithIndex")
        End Try
    End Sub

    'Public Shared Function IsNewComboItem(ByRef cmbBox As ComboBox) As Boolean

    '    Dim dtbSource As DataTable
    '    Dim intCount As Integer
    '    dtbSource = cmbBox.DataSource
    '    For intCount = 0 To dtbSource.Rows.Count - 1
    '    Next
    '    Return False


    'End Function

    Public Shared Function GetCounters() As DataTable
        Return DGeneral.GetCounters()
    End Function
    '...                24/08/2007
    Public Shared Function GetCounter() As DataTable
        Return DGeneral.GetCounter().Tables(0)
    End Function

    Public Shared Sub SetListValues(ByRef lstbox As ListBox, ByVal dttable As DataTable, ByVal ValueMember As String, ByVal DispMember As String)
        Try

            lstbox.DataSource = dttable
            lstbox.ValueMember = dttable.Columns(ValueMember).ToString()
            lstbox.DisplayMember = dttable.Columns(DispMember).ToString()

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetListValues")
        End Try
    End Sub

    Public Shared Function GetConfigValues(ByVal key As String) As String
        Try
            Return ConfigurationManager.AppSettings(key)
        Catch ex As Exception
            Return ""
        End Try

    End Function

    Public Shared Function GetTaxes() As DataTable
        Return DGeneral.GetTaxes()
    End Function

    Public Shared Function IsInteger(ByVal Text As String) As Boolean
        'Return True if Text can be convert into Integer
        Dim intCount As Integer
        Dim strIntegers As String = "0123456789."
        Dim chrArray() As Char = Text.ToCharArray()

        For intCount = 0 To chrArray.Length - 1
            If strIntegers.IndexOf(chrArray(intCount)) < 0 Then
                ShowMsgError(10101)
                Return False
                Exit Function
            End If
        Next
        Return True
    End Function
    Public Shared Function CheckInteger(ByVal Text As String) As Boolean
        'Return True if Text can be convert into Integer
        Dim intCount As Integer
        Dim strIntegers As String = "0123456789."
        Dim chrArray() As Char = Text.ToCharArray()

        For intCount = 0 To chrArray.Length - 1
            If strIntegers.IndexOf(chrArray(intCount)) < 0 Then
                Return False
                Exit Function
            End If
        Next
        Return True
    End Function

    Public Shared Function IsFloat(ByVal Text As String) As Boolean
        'Return True if Text can be convert into Float Or Double
        Dim intCount As Integer
        Dim strIntegers As String = ".0123456789"
        Dim chrArray() As Char = Text.ToCharArray()

        For intCount = 0 To chrArray.Length - 1
            If strIntegers.IndexOf(chrArray(intCount)) < 0 Then
                ShowMsgError(10102)
                Return False
                Exit Function
            End If
        Next
        Return True
    End Function

    Public Shared Function IsChar(ByVal Text As String) As Boolean
        'Return True if Text can be convert into Char

        If Text.Length > 1 Then
            ShowMsgError(10103)
            Return False
            Exit Function
        Else
            Return True
        End If
    End Function

    Public Shared Function GetSequentialID(ByVal objDocType As DGeneral.DocTypes) As String
        Return DGeneral.GetSeqNum(objDocType)
    End Function
    Public Shared Function GetSeqNum(ByVal Category As String)
        Return DGeneral.GetSeqNum(Category, False)
    End Function
    Public Shared Function GetSequentialCode(ByVal Category As String) As String
        Return DGeneral.GetSeqNum(Category)
    End Function
    Public Shared Function GetFirmName() As String
        Return DGeneral.GetFirmName()
    End Function
    Public Shared Function GetFirmFullName() As String
        Return DGeneral.GetFirmFullName()
    End Function
    ' 22/11/2007
    Public Shared Function GetDatePicker() As DataTable
        Return DGeneral.GetDatePicker()
    End Function
    '@ on 20071205:Added for Getting Vendor 
    Public Shared Function GetVendor(ByVal Company As Integer) As DataTable
        Return DGeneral.GetVendor(Company)
    End Function

    Public Shared Function ChkNullVal(ByVal chkVal, ByVal ReplaceVal) As String
        Return IIf(IsDBNull(chkVal), ReplaceVal, chkVal)
    End Function


    Public Shared Function GetReportHeading(ByVal ReportName As String) As String
        Dim StrReportHeading As String = ""
        Try
            Select Case ReportName
                Case "VendorWiseStock"                                  '1
                    StrReportHeading = "Vendor Wise Stock Report"
                Case "CompanyWiseStock"                                 '2
                    StrReportHeading = "Company Wise Stock Report"
                Case "ShelfWiseStock"                                   '3
                    StrReportHeading = "Location Wise Stock Report"
                Case "ItemsNearToExpiry"                                '4
                    StrReportHeading = "Items Near to Expiry Date"
                Case "ExpiredStock"                                     '5
                    StrReportHeading = " Expired Item stock"
                Case "PurchaseInvoices"                                 '6
                    StrReportHeading = "Purchase Invoice"
                Case "DelliveryChallan"     'Incomplete                 '7
                    StrReportHeading = "Dellivery Challan"
                Case "DelliveryChallanToPI" 'Incomplete                 '8
                    StrReportHeading = "Dellivery Challan To Invoice"
                Case "SaleBill"                                         '9
                    StrReportHeading = "Sale Bill"
                Case "CounterSale"                                      '10
                    StrReportHeading = "Counter Sale Report"
                Case "VendorWiseSale"                                   '11
                    StrReportHeading = "VendorWise Sale Report"
                Case "ItemWiseSale"                                     '12
                    StrReportHeading = "Item Wise Sale Report"
                Case "DateWiseSale"                                     '13
                    StrReportHeading = "Date Wise Sale Report"
                Case "PurchaseReturn"                                   '14
                    StrReportHeading = "Purchase Return Report"
                Case "SaleReturn"                                       '15
                    StrReportHeading = "Sale Return Report"
                Case "PaymentReceipt"                                   '16
                    StrReportHeading = "Payment Reciept"
                Case "VendorPayment"                                    '17
                    StrReportHeading = "Vendor Payments"
                Case "PendingPayments"                                  '18
                    StrReportHeading = "Pending Payments"
                Case "OutStandingPayments"                              '19
                    StrReportHeading = "Outstanding Payments"
                Case "PurchaseRegister"                                 '20
                    StrReportHeading = "Purchase Register"
                Case "SaleRegister"                                     '21
                    StrReportHeading = "Sale Register"
            End Select
            Return StrReportHeading
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "GetReportHeading")
            Return ""
        End Try
    End Function

    Public Shared Function CheckSeqID(ByVal SeqID As String, ByVal DocType As String) As Integer
        'Return True if seqid is available in current table 
        Return DGeneral.CheckSeqID(SeqID, DocType)
        'Return True
    End Function
    'if the value is zero then will return Blank String else convert the val to String 
    Public Shared Function InttoBlank(ByVal Val As Integer) As String
        Return IIf(Val = 0, "", CStr(Val))
    End Function
    Public Shared Function GetCheckedIdList(ByVal basectrl As Windows.Forms.CheckedListBox) As String
        Dim i As Integer
        Dim sb As New StringBuilder

        For i = 0 To basectrl.CheckedIndices.Count - 1

            If sb.Length.Equals(0) Then
                sb.Append("'" & basectrl.Items.Item(basectrl.CheckedIndices.Item(i)).item(0) & "'")
            Else
                sb.Append(",'")
                sb.Append(basectrl.Items.Item(basectrl.CheckedIndices.Item(i)).item(0))
                sb.Append("'")
            End If
        Next
        Return sb.ToString
    End Function
    Public Shared Function GetDatewithLastDay(ByVal value As Date) As Date

        Return New Date(value.Year, value.Month, Date.DaysInMonth(value.Year, value.Month))

        'Dim orgval As String
        'Dim pattern As String
        'Dim sep As String
        'Dim patarr() As String
        'Dim valarr() As String
        'Dim i As Integer
        'Dim yy As Integer
        'Dim dd As Integer
        'Dim mm As Integer
        'Dim intday As Integer
        'pattern = Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern
        'sep = Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.DateSeparator
        'orgval = value.Date
        'patarr = pattern.Split(sep)
        'valarr = orgval.Split(sep)
        'For i = 0 To UBound(patarr)
        '    Select Case Mid(patarr(i), 1, 1).ToUpper
        '        Case "M"
        '            mm = CInt(valarr(i))
        '        Case "Y"
        '            yy = CInt(valarr(i))
        '        Case "D"
        '            dd = CInt(valarr(i))
        '    End Select
        'Next
        'intday = Date.DaysInMonth(yy, mm)
        'Dim gg As Globalization.Calendar
        'gg = Globalization.CultureInfo.CurrentUICulture.Calendar
        'yy = gg.ToFourDigitYear(yy)
        'Dim d As Date
        'd = New Date(yy, mm, intday)
        'Return d
    End Function
    'ADDED BY  ON DEC-30-2007
    Public Shared Function GetDate(ByVal value As String) As Date
        Dim orgval As String
        Dim pattern As String
        Dim sep As String
        Dim patarr() As String
        Dim valarr() As String
        Dim i As Integer
        Dim yy As Integer
        Dim dd As Integer
        Dim mm As Integer
        'pattern = Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern
        'sep = Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.DateSeparator
        pattern = "dd/MM/yyyy" 'Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern
        sep = "/" 'Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.DateSeparator

        orgval = value
        patarr = pattern.Split(sep)
        valarr = orgval.Split(sep)
        For i = 0 To UBound(patarr)
            Select Case Mid(patarr(i), 1, 1).ToUpper
                Case "M"
                    mm = CInt(valarr(i))
                Case "Y"
                    yy = CInt(valarr(i))
                Case "D"
                    dd = CInt(valarr(i))
            End Select
        Next

        Dim d As Date
        d = New Date(yy, mm, dd)
        Return d


    End Function
    'ADDED BY  ON JAN-09-2007
    Public Shared Function GetDBDate(ByVal value As String) As String
        Dim sep As String
        Dim valarr() As String
        Dim dbdate As String
        'DATE FORMAT WE ARE USING 
        '"dd/MM/yyyy"
        sep = "/"
        'DATE FORMAT REQUIRED FOR DATABASE --mdy
        '"MM/dd/yyyy"
        valarr = value.Split(sep)
        dbdate = valarr(1) & sep & valarr(0) & sep & valarr(2)
        Return dbdate
    End Function
    'Code End    

    Public Shared Function GetCounterColor(ByVal intCounterNo As Integer) As Drawing.Color
        Dim AppConts As New CConstants
        Try
            Return AppConts.CntColor(intCounterNo - 1)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "GetReportHeading")
            Return CConstants.NormalCntColor
        Finally
            AppConts = Nothing
        End Try
    End Function
    'Public Shared Sub SetFlexGrid(ByRef cfg As C1.Win.C1FlexGrid.C1FlexGrid)
    '    Try
    '        Dim Fnt As Font = New Font("Verdana", 8, FontStyle.Regular)
    '        Dim HdFnt As Font = New Font("Verdana", 8, FontStyle.Bold)
    '        With cfg
    '            'CONTROL SETTINGS 
    '            .BorderStyle = Util.BaseControls.BorderStyleEnum.FixedSingle
    '            .BackColor = Color.LightSteelBlue
    '            .AllowResizing = AllowResizingEnum.None
    '            .AllowDragging = AllowDraggingEnum.None
    '            .AllowFreezing = AllowFreezingEnum.None
    '            '.ShowCellLabels = True
    '            'ROW SETTINGS
    '            '.Styles.Normal.BackColor = Color.FromArgb(223, 241, 253)
    '            '.Styles.Normal.BackColor = Color.FromArgb(250, 243, 218)
    '            .Styles.Normal.BackColor = Color.FromArgb(247, 247, 247)
    '            '.Styles.Normal.BackColor = Color.FromArgb(244, 250, 253)
    '            .Styles.Normal.Border.Style = C1.Win.C1FlexGrid.BorderStyleEnum.Flat

    '            '.Styles.Normal.Border.Color = Color.FromArgb(79, 112, 165)
    '            .Styles.Normal.Border.Color = Color.FromArgb(230, 230, 230)
    '            .Styles.Normal.Border.Direction = BorderDirEnum.Vertical
    '            .Styles.Normal.ForeColor = Color.Black
    '            .Styles.Fixed.Font = Fnt
    '            'ALTERNATE COLOR 
    '            .Styles.Alternate.BackColor = Color.White   'Aqua
    '            .Styles.Alternate.ForeColor = Color.Black
    '            'HEADER
    '            '.Styles.Fixed.BackColor = Color.FromArgb(79, 112, 165)   'Chocolate
    '            '.Styles.Fixed.BackColor = Color.FromArgb(4, 55, 102)   'Chocolate
    '            .Styles.Fixed.BackColor = Color.FromArgb(13, 104, 159)   'Chocolate
    '            .Styles.Fixed.Border.Style = C1.Win.C1FlexGrid.BorderStyleEnum.None
    '            '.Styles.Fixed.ForeColor = Color.FromArgb(223, 241, 253)
    '            .Styles.Fixed.ForeColor = Color.White
    '            .Styles.Fixed.TextAlign = TextAlignEnum.CenterCenter
    '            .Styles.Fixed.Font = HdFnt
    '            'EMPTY AREA 
    '            '.Styles.EmptyArea.BackColor = Color.FromArgb(204, 224, 248)
    '            .Styles.EmptyArea.BackColor = Color.AliceBlue

    '            'FOCUS
    '            '.Styles.Focus.Border.Direction = BorderDirEnum.Vertical
    '            'HIGHLIGHT
    '            .Styles.Highlight.BackColor = Color.SlateGray
    '        End With
    '    Catch ex As Exception
    '        BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetFlexGrid")
    '    End Try
    'End Sub
#Region "TEXT VALIDATION FUNCTIONS"
    'Code Start                     ....17/04/2007

    Public Shared Function ValidateEmailID(ByVal EmailID As String) As Boolean
        Try
            Dim sEXT As String = EmailID
            Dim mEXT As String = EmailID
            Dim strTmp As String
            Dim n As Integer
            Dim ValidateEmail As Boolean = True
            Do While InStr(1, sEXT, ".") <> 0
                sEXT = Right(sEXT, Len(sEXT) - InStr(1, sEXT, "."))
            Loop

            Do While InStr(1, mEXT, "@") <> 0
                mEXT = Right(mEXT, Len(mEXT) - InStr(1, mEXT, "@"))
            Loop

            If InStr(1, mEXT, ".") = 1 Then
                ValidateEmail = False
            ElseIf InStr(1, EmailID, "@") = 0 Then
                ValidateEmail = False                   ' Your email address does not contain an @ sign."
            ElseIf InStr(1, EmailID, "@") = 1 Then      ' Your @ sign can not be the first character in your email address!"
                ValidateEmail = False
            ElseIf InStr(1, EmailID, ".") = 1 Then      ' Your . sign can not be the first character in your email address!"
                ValidateEmail = False
            ElseIf InStr(1, EmailID, "@") = Len(EmailID) Then ' Your @ sign can not be the last character in your email address!"
                ValidateEmail = False
            ElseIf InStr(1, EmailID, ".") = Len(EmailID) Then ' Your . sign can not be the last character in your email address!"
                ValidateEmail = False
            ElseIf EXTisOK(sEXT) = False Then           ' Your email address is not carrying a valid ending(Like  .com, .net, .gov, .org, .edu, .biz, .tv)"
                ValidateEmail = False
            ElseIf Len(EmailID) < 6 Then                'Your email address is shorter than 6 characters which is impossible."
                ValidateEmail = False
            End If
            strTmp = EmailID
            Do While InStr(1, strTmp, "@") <> 0
                n = n + 1
                strTmp = Right(strTmp, Len(strTmp) - InStr(1, strTmp, "@"))
            Loop
            If n > 1 Then
                ValidateEmail = False                   ' You have more than 1 @ sign in your email address"
            End If

            ' 28/11/2007
            n = 0
            strTmp = EmailID
            Do While InStr(1, strTmp, ".") <> 0
                n = n + 1
                strTmp = Right(strTmp, Len(strTmp) - InStr(1, strTmp, "."))
            Loop
            If n > 2 Then
                ValidateEmail = False                   ' You have more than 2 . sign in your email address"
            End If
            'End 
            If ValidateEmail = False Then
                ShowMsgError(10105)
            End If
            Return ValidateEmail

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "ValidateEmailID")
        End Try
    End Function

    Public Shared Function ValidateWebAddr(ByVal WebAddr As String) As Boolean
        Try
            Dim sEXT As String = WebAddr
            Dim strTmp As String
            Dim n As Integer
            Dim ValidateWeb As Boolean = True
            Do While InStr(1, sEXT, ".") <> 0
                sEXT = Right(sEXT, Len(sEXT) - InStr(1, sEXT, "."))
            Loop

            If InStr(1, WebAddr, "@") = 0 Then
                ValidateWeb = False                   ' Your WeDAddress does not contain an @ sign."
            ElseIf InStr(1, WebAddr, "@") = 1 Then      ' Your @ sign can not be the first character in your WeDAddress!"
                ValidateWeb = False
            ElseIf InStr(1, WebAddr, ".") = 1 Then      ' Your . sign can not be the first character in your WeDAddress!"
                ValidateWeb = False
            ElseIf InStr(1, WebAddr, "@") = Len(WebAddr) Then ' Your @ sign can not be the last character in your WeDAddress!"
                ValidateWeb = False
            ElseIf InStr(1, WebAddr, ".") = Len(WebAddr) Then ' Your . sign can not be the last character in your WeDAddress!"
                ValidateWeb = False
            ElseIf EXTisOK(sEXT) = False Then           ' Your WeDAddress is not carrying a valid ending(Like  .com, .net, .gov, .org, .edu, .biz, .tv)"
                ValidateWeb = False
            ElseIf Len(WebAddr) < 6 Then                'Your WeDAddress is shorter than 6 characters which is impossible."
                ValidateWeb = False
            End If
            strTmp = WebAddr
            Do While InStr(1, strTmp, "@") <> 0
                n = n + 1
                strTmp = Right(strTmp, Len(strTmp) - InStr(1, strTmp, "@"))
            Loop
            If n > 1 Then
                ValidateWeb = False                   ' You have more than 1 @ sign in your WeDAddress"
            End If

            n = 0
            strTmp = WebAddr
            Do While InStr(1, strTmp, ".") <> 0
                n = n + 1
                strTmp = Right(strTmp, Len(strTmp) - InStr(1, strTmp, "."))
            Loop
            If n > 2 Then
                ValidateWeb = False                   ' You have more than 2 . sign in your WeDAddress"
            End If

            If ValidateWeb = False Then
                ShowMsgError(10107)
            End If
            Return ValidateWeb

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "ValidateWebAddr")
        End Try
    End Function

    Public Shared Function EXTisOK(ByVal sEXT As String) As Boolean
        Dim EXT As String = "" ', X As Long
        EXTisOK = False
        If Left(sEXT, 1) <> "." Then sEXT = "." & sEXT
        sEXT = UCase(sEXT) 'just to avoid errors 
        EXT = EXT & ".COM.EDU.GOV.NET.BIZ.ORG.TV"
        EXT = EXT & ".AF.AL.DZ.As.AD.AO.AI.AQ.AG.AP.AR.AM.AW.AU.AT.AZ.BS.BH.BD.BB.BY"
        EXT = EXT & ".BE.BZ.BJ.BM.BT.BO.BA.BW.BV.BR.IO.BN.BG.BF.MM.BI.KH.CM.CA.CV.KY"
        EXT = EXT & ".CF.TD.CL.CN.CX.CC.CO.KM.CG.CD.CK.CR.CI.HR.CU.CY.CZ.DK.DJ.DM.DO"
        EXT = EXT & ".TP.EC.EG.SV.GQ.ER.EE.ET.FK.FO.FJ.FI.CS.SU.FR.FX.GF.PF.TF.GA.GM.GE.DE"
        EXT = EXT & ".GH.GI.GB.GR.GL.GD.GP.GU.GT.GN.GW.GY.HT.HM.HN.HK.HU.IS.IN.ID.IR.IQ"
        EXT = EXT & ".IE.IL.IT.JM.JP.JO.KZ.KE.KI.KW.KG.LA.LV.LB.LS.LR.LY.LI.LT.LU.MO.MK.MG"
        EXT = EXT & ".MW.MY.MV.ML.MT.MH.MQ.MR.MU.YT.MX.FM.MD.MC.MN.MS.MA.MZ.NA"
        EXT = EXT & ".NR.NP.NL.AN.NT.NC.NZ.NI.NE.NG.NU.NF.KP.MP.NO.OM.PK.PW.PA.PG.PY"
        EXT = EXT & ".PE.PH.PN.PL.PT.PR.QA.RE.RO.RU.RW.GS.SH.KN.LC.PM.ST.VC.SM.SA.SN.SC"
        EXT = EXT & ".SL.SG.SK.SI.SB.SO.ZA.KR.ES.LK.SD.SR.SJ.SZ.SE.CH.SY.TJ.TW.TZ.TH.TG.TK"
        EXT = EXT & ".TO.TT.TN.TR.TM.TC.TV.UG.UA.AE.UK.US.UY.UM.UZ.VU.VA.VE.VN.VG.VI"
        EXT = EXT & ".WF.WS.EH.YE.YU.ZR.ZM.ZW"
        EXT = UCase(EXT) 'just to avoid errors 
        If InStr(1, EXT, sEXT, vbBinaryCompare) <> 0 Then EXTisOK = True
    End Function

    'Code Start                                                      ....29/06/2007 

    Public Shared Function ValidateText(ByVal KeyCode As Integer, ByVal TextType As String, Optional ByVal p_blnDecimal As Boolean = False) As Boolean
        'KeyCode from 65 To 91 for char values
        'KeyCode 48 to 58 -> Numbers on TextPad
        'KeyCode 96 to 106 -> Numbers on NumPad
        'KeyCode 37-> Left Arrowkey & 39-> Right Arrowkey & 46->Delete Key
        'KeyCode 35-> End Key & 36-> Home Key & 222->Single Quote
        'KeyCode 188->"," Comma & 189-> "-" dash & 190->"." dot  


        Try
            If TextType = "ALF" Then
                If (KeyCode >= 65 And KeyCode <= 65 + 26) Or _
                        (KeyCode = 32) Or (KeyCode = 190) Or _
                        (KeyCode = 8) Or (KeyCode = 13) Or (KeyCode = 19) Or _
                        (KeyCode = 37) Or (KeyCode = 39) Or (KeyCode = 46) Or _
                        (KeyCode = 35) Or (KeyCode = 36) Or _
                        (KeyCode = 3) Or (KeyCode = 12) Or (KeyCode = 222) Or (KeyCode = 27) Then '(KeyCode >= 97 And KeyCode <= 97 + 26) Or
                    ValidateText = True
                Else
                    ValidateText = False
                    Exit Function
                End If

                If KeyCode = 91 Or KeyCode = 123 Then
                    ValidateText = False
                End If
            End If

            If TextType = "NUM" Then
                If KeyCode = 16 Then Return False
                '@20071211 : Comment existing IF condition and write it again with changes
                'Previously it was 
                'If (KeyCode >= 48 And KeyCode <= 48 + 10) Or (KeyCode >= 96 And KeyCode <= 96 + 10) Or (KeyCode = 32) Or _
                If (KeyCode >= 48 And KeyCode <= 48 + 10) Or (KeyCode >= 96 And KeyCode < 96 + 10) Or _
                        (KeyCode = 13) Or (KeyCode = 8) Or (KeyCode = 19) Or _
                        (KeyCode = 37) Or (KeyCode = 39) Or (KeyCode = 46) Or _
                        (KeyCode = 35) Or (KeyCode = 36) Or (KeyCode = 110) Or (KeyCode = 190) Or _
                        (KeyCode = 3) Or (KeyCode = 12) Or (KeyCode = 27) Then
                    ValidateText = True
                Else
                    If p_blnDecimal And KeyCode = 46 Then
                        ValidateText = True
                    Else
                    End If
                End If
                If KeyCode = 91 Or KeyCode = 123 Or KeyCode = 58 Then
                    ValidateText = False
                End If
            End If

            If TextType = "ALFNUM" Then
                '@20071211 : Comment existing IF condition and write it again with changes
                'Previously it was 
                '(KeyCode >= 96 And KeyCode < 96= + 10) Or (KeyCode = 32) Or _
                '(KeyCode = 188) Or (KeyCode = 189) Or (KeyCode = 190) Or _
                If (KeyCode >= 65 And KeyCode <= 65 + 26) Or _
                        (KeyCode >= 96 And KeyCode < 96 + 10) Or (KeyCode = 32) Or _
                        (KeyCode = 8) Or (KeyCode = 13) Or (KeyCode = 46) Or _
                        (KeyCode >= 45 And KeyCode <= 45 + 12) Or (KeyCode = 32) Or _
                        (KeyCode = 37) Or (KeyCode = 39) Or (KeyCode = 46) Or _
                        (KeyCode = 35) Or (KeyCode = 36) Or _
                        (KeyCode = 189) Or (KeyCode = 191) Or (KeyCode = 190) Or _
                        (KeyCode = 19) Or (KeyCode = 3) Or (KeyCode = 27) Then
                    ValidateText = True
                Else
                    ValidateText = False
                End If
            End If

            If TextType = "ALFTEXT" Then
                If (KeyCode >= 65 And KeyCode <= 65 + 26) Or _
                        (KeyCode >= 96 And KeyCode < 96 + 10) Or (KeyCode = 32) Or _
                        (KeyCode = 8) Or (KeyCode = 13) Or (KeyCode = 46) Or _
                        (KeyCode >= 45 And KeyCode <= 45 + 12) Or (KeyCode = 32) Or _
                        (KeyCode = 37) Or (KeyCode = 39) Or (KeyCode = 46) Or _
                        (KeyCode = 35) Or (KeyCode = 36) Or (KeyCode = 220) Or _
                        (KeyCode = 189) Or (KeyCode = 191) Or (KeyCode = 190) Or (KeyCode = 188) Or _
                        (KeyCode = 19) Or (KeyCode = 3) Or (KeyCode = 27) Then
                    ValidateText = True
                Else
                    ValidateText = False
                End If
            End If
            Exit Function
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "ValidateText")
        End Try
    End Function
    ' 23/10/2007                                                  
    Public Shared Function ValidateMiscell(ByVal KeyCode As Integer, ByVal TextType As String) As Boolean
        'KeyCode 96 to 105 -> Numbers on NumPad
        '95->Underscore & 8->Backspace  

        Try
            If TextType = "USERID" Then
                If (KeyCode >= 65 And KeyCode <= 65 + 26) Or (KeyCode = 95) Or (KeyCode = 32) Or _
                         (KeyCode = 189) Or (KeyCode = 190) Or (KeyCode = 46) Or (KeyCode = 8) Or _
                         (KeyCode = 35) Or (KeyCode = 36) Or (KeyCode = 37) Or (KeyCode = 39) Or _
                         (KeyCode >= 48 And KeyCode <= 58) Or (KeyCode >= 96 And KeyCode <= 105) Then
                    ValidateMiscell = True
                Else
                    ValidateMiscell = False
                    Exit Function
                End If
            End If
            If TextType = "PSWRD" Then
                If (KeyCode >= 65 And KeyCode <= 65 + 26) Or _
                         (KeyCode = 46) Or (KeyCode = 8) Or _
                         (KeyCode = 35) Or (KeyCode = 36) Or (KeyCode = 37) Or (KeyCode = 39) Or _
                         (KeyCode >= 48 And KeyCode <= 58) Or (KeyCode >= 96 And KeyCode <= 105) Then
                    ValidateMiscell = True
                Else
                    ValidateMiscell = False
                    Exit Function
                End If
            End If
            If TextType = "AMOUNT" Then
                If (KeyCode >= 48 And KeyCode <= 58) Or (KeyCode >= 96 And KeyCode <= 105) Or _
                        (KeyCode = 46) Or (KeyCode = 8) Or _
                        (KeyCode = 35) Or (KeyCode = 36) Or (KeyCode = 37) Or (KeyCode = 39) Or _
                        (KeyCode = 190) Then
                    ValidateMiscell = True
                Else
                    ValidateMiscell = False
                    Exit Function
                End If
            End If
            If TextType = "QTY" Then
                If (KeyCode >= 48 And KeyCode <= 58) Or (KeyCode >= 96 And KeyCode <= 105) Or _
                        (KeyCode = 46) Or (KeyCode = 8) Or _
                        (KeyCode = 35) Or (KeyCode = 36) Or (KeyCode = 37) Or (KeyCode = 39) Then
                    ValidateMiscell = True
                Else
                    ValidateMiscell = False
                    Exit Function
                End If
            End If
            If TextType = "PHONE" Then
                If (KeyCode >= 48 And KeyCode <= 58) Or (KeyCode >= 96 And KeyCode <= 105) Or _
                        (KeyCode = 46) Or (KeyCode = 8) Or _
                        (KeyCode = 35) Or (KeyCode = 36) Or (KeyCode = 37) Or (KeyCode = 39) Then
                    ValidateMiscell = True
                Else
                    ValidateMiscell = False
                    Exit Function
                End If
            End If
            Exit Function

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "ValidateMiscell")
        End Try
    End Function

#End Region '"TEXT VALIDATION FUNCTIONS"
    '@ on 20071211;Added for Bydefault value set from mpref.
    Public Shared Function SetDefault(ByVal PrefName As String) As String
        Dim StrSql As String = ""
        Try
            StrSql = "SELECT PrefValue FROM mprefs WHERE PrefName='" & PrefName & "'"
            Return DbHelper.ExecuteScalar(StrSql)
        Catch ex As Exception
            DGeneral.ErrorHandler(ex.Message, "BAL", "BCommon", "SetDefault", StrSql)
            Return ""
        End Try
    End Function
    '@20071211 : Add New Function to remove Multiple Decimal Point Problem
    Public Shared Function ValidateText(ByVal TextVal As String, ByVal KeyCode As Integer, ByVal TextType As String, Optional ByVal p_blnDecimal As Boolean = False) As Boolean
        'KeyCode from 65 To 91 for char values
        'KeyCode 48 to 58 -> Numbers on TextPad
        'KeyCode 96 to 106 -> Numbers on NumPad
        'KeyCode 37-> Left Arrowkey & 39-> Right Arrowkey & 46->Delete Key
        'KeyCode 35-> End Key & 36-> Home Key & 222->Single Quote
        'KeyCode 188->"," Comma & 189-> "-" dash & 190->"." dot  

        Dim count As Integer
        Dim strTmp As String
        Try
            If TextType = "ALF" Then
                If (KeyCode >= 65 And KeyCode <= 65 + 26) Or _
                         (KeyCode = 32) Or _
                        (KeyCode = 8) Or (KeyCode = 13) Or (KeyCode = 19) Or _
                        (KeyCode = 37) Or (KeyCode = 39) Or (KeyCode = 46) Or _
                        (KeyCode = 35) Or (KeyCode = 36) Or _
                        (KeyCode = 3) Or (KeyCode = 12) Or (KeyCode = 27) Then '(KeyCode >= 97 And KeyCode <= 97 + 26) Or
                    ValidateText = True
                Else
                    ValidateText = False
                    Exit Function
                End If

                If KeyCode = 91 Or KeyCode = 123 Then
                    ValidateText = False
                End If
            End If

            If TextType = "NUM" Then
                If (KeyCode = 190 OrElse KeyCode = 110) Then
                    strTmp = TextVal
                    Do While InStr(1, strTmp, ".") <> 0
                        count = count + 1
                        strTmp = Right(strTmp, Len(strTmp) - InStr(1, strTmp, "."))
                    Loop
                    If count = 1 Then
                        ValidateText = False
                        Exit Function ' You have more than 1 (Decimal . Point)
                    End If
                End If
                If KeyCode = 16 Then Return False
                If (KeyCode >= 48 And KeyCode <= 48 + 10) Or (KeyCode >= 96 And KeyCode < 96 + 10) Or (KeyCode = 32) Or _
                        (KeyCode = 13) Or (KeyCode = 8) Or (KeyCode = 19) Or _
                        (KeyCode = 37) Or (KeyCode = 39) Or (KeyCode = 46) Or _
                        (KeyCode = 35) Or (KeyCode = 36) Or (KeyCode = 110) Or (KeyCode = 190) Or _
                        (KeyCode = 3) Or (KeyCode = 12) Or (KeyCode = 27) Then
                    ValidateText = True
                Else
                    If p_blnDecimal And KeyCode = 46 Then
                        ValidateText = True
                    Else
                    End If
                End If
                If KeyCode = 91 Or KeyCode = 123 Or KeyCode = 58 Then
                    ValidateText = False
                End If
            End If

            If TextType = "ALFNUM" Then
                If (KeyCode = 190) Then
                    strTmp = TextVal
                    Do While InStr(1, strTmp, ".") <> 0
                        count = count + 1
                        strTmp = Right(strTmp, Len(strTmp) - InStr(1, strTmp, "."))
                    Loop
                    If count = 1 Then
                        ValidateText = False
                        Exit Function ' You have more than 1 (Decimal . Point)
                    End If
                End If
                If (KeyCode >= 65 And KeyCode <= 65 + 26) Or _
                        (KeyCode >= 96 And KeyCode <= 96 + 10) Or (KeyCode = 32) Or _
                        (KeyCode = 8) Or (KeyCode = 13) Or (KeyCode = 46) Or _
                        (KeyCode >= 45 And KeyCode <= 45 + 12) Or (KeyCode = 32) Or _
                        (KeyCode = 37) Or (KeyCode = 39) Or (KeyCode = 46) Or _
                        (KeyCode = 35) Or (KeyCode = 36) Or _
                        (KeyCode = 188) Or (KeyCode = 189) Or (KeyCode = 190) Or _
                        (KeyCode = 19) Or (KeyCode = 3) Or (KeyCode = 27) Then
                    ValidateText = True
                Else
                    ValidateText = False
                End If
            End If
            Exit Function
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "ValidateText")
        End Try
    End Function
    '@ on 20071211:Added for WebSite Address Validation 
    Public Shared Function ValidateWebAdd(ByVal WebAdd As String) As Boolean

        Try
            Dim arr As String = ".com,.net,.org,.biz,.coop,.info,.museum,.name, " & _
                                ".pro,.edu,.gov,.int,.mil,.ac,.ad,.ae,.af,.ag, " & _
                                ".ai, .al, .am, .an, .ao, .aq, .ar, .as, .at, .au, .aw, " & _
            ".az, .ba, .bb, .bd, .be, .bf, .bg, .bh, .bi, .bj, .bm, " & _
            ".bn, .bo, .br, .bs, .bt, .bv, .bw, .by, .bz, .ca, .cc, " & _
            ".cd, .cf, .cg, .ch, .ci, .ck, .cl, .cm, .cn, .co, .cr, " & _
            ".cu, .cv, .cx, .cy, .cz, .de, .dj, .dk, .dm, .do, .dz, " & _
            ".ec, .ee, .eg, .eh, .er, .es, .et, .fi, .fj, .fk, .fm, " & _
            ".fo, .fr, .ga, .gd, .ge, .gf, .gg, .gh, .gi, .gl, .gm, " & _
            ".gn, .gp, .gq, .gr, .gs, .gt, .gu, .gv, .gy, .hk, .hm, " & _
            ".hn, .hr, .ht, .hu, .id, .ie, .il, .im, .in, .io, .iq, " & _
            ".ir, .is, .it, .je, .jm, .jo, .jp, .ke, .kg, .kh, .ki, " & _
            ".km, .kn, .kp, .kr, .kw, .ky, .kz, .la, .lb, .lc, .li, " & _
            ".lk, .lr, .ls, .lt, .lu, .lv, .ly, .ma, .mc, .md, .mg, " & _
            ".mh, .mk, .ml, .mm, .mn, .mo, .mp, .mq, .mr, .ms, .mt, " & _
            ".mu, .mv, .mw, .mx, .my, .mz, .na, .nc, .ne, .nf, .ng, " & _
            ".ni, .nl, .no, .np, .nr, .nu, .nz, .om, .pa, .pe, .pf, " & _
            ".pg, .ph, .pk, .pl, .pm, .pn, .pr, .ps, .pt, .pw, .py, " & _
            ".qa, .re, .ro, .rw, .ru, .sa, .sb, .sc, .sd, .se, .sg, " & _
            ".sh, .si, .sj, .sk, .sl, .sm, .sn, .so, .sr, .st, .sv, " & _
            ".sy, .sz, .tc, .td, .tf, .tg, .th, .tj, .tk, .tm, .tn, " & _
            ".to, .tp, .tr, .tt, .tv, .tw, .tz, .ua, .ug, .uk, .um, " & _
            ".us, .uy, .uz, .va, .vc, .ve, .vg, .vi, .vn, .vu, .ws, " & _
            ".wf, .ye, .yt, .yu, .za, .zm, .zw,"

            Dim mai As String = WebAdd
            ''Dim val As Boolean = True
            Dim dot As Integer = mai.LastIndexOf(".")  'Gets Dot position 
            Dim Dotfirst As Integer = mai.IndexOf(".")  '@20072112 Add Variable to get First position of dot

            '' ''If dot < 0 Then ValidateWebAdd = False : Exit Function

            '@20072112 : comment following single line and if condition again by making some change
            'If dot < 0 Then BCommon.ShowMsgError(10107) : Return False : Exit Function
            If Dotfirst < 0 Then BCommon.ShowMsgError(10107) : Return False : Exit Function
            If WebAdd.Substring(0, 3) = "www" Then
                If WebAdd.Substring(3, 1) <> "." Then
                    BCommon.ShowMsgError(10107) : Return False : Exit Function 'Domain Name not proper
                    Exit Function
                End If
            End If

            Dim AddWithoutExtention As String = mai.Substring(0, dot)
            Dim ext As String = mai.Substring(dot)
            ''Dim i As Integer = 0
            Dim j As Integer = 0

            If dot > 2 AndAlso dot < 57 Then  'Web address must be less than 56 charectres
                If InStr(1, arr, ext & ",", CompareMethod.Text) = 0 Then
                    '' ''ValidateWebAdd = False 'Your domain extension "+ext+" is not correct"
                    BCommon.ShowMsgError(10107) : Return False : Exit Function  'Your domain extension "+ext+" is not correct
                Else
                    'For j = 0 To j < AddWithoutExtention.Length
                    Do While j < AddWithoutExtention.Length

                        'Dim dh As String = AddWithoutExtention.charAt(j)
                        Dim dh As String = AddWithoutExtention.Substring(j, 1)
                        'Dim hh As String = dh.charCodeAt(0)
                        Dim hh As Integer = Asc(dh)
                        If ((hh > 47 And hh < 59) Or (hh > 64 And hh < 91) Or (hh > 96 And hh < 123) Or (hh = 45 Or hh = 46)) Then
                            If ((j = 0 Or j = AddWithoutExtention.Length - 1) And hh = 45) Then
                                'MsgBox("Domain name should not begin or end with '-'")
                                BCommon.ShowMsgError(10107)
                                Return False
                            End If

                        Else
                            'MsgBox("Your domain name should not have special characters")
                            BCommon.ShowMsgError(10107)
                            Return False
                        End If
                        j = j + 1
                    Loop
                    'Next
                    ValidateWebAdd = True
                End If
            End If

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "ValidateWebAdd")
        End Try
    End Function

    Public Shared Function FirmInfo() As DataTable
        Try
            Return DGeneral.FirmInfo()

        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "FirmInfo")
            Return Nothing
        End Try
    End Function


    Public Shared Function FormatAmount(ByVal Amount As Double) As String
        Try
            Dim StringAmount As String
            If InStr(Amount.ToString(), ",") Then
                StringAmount = Amount.ToString.Replace(",", "")
            Else
                StringAmount = Amount.ToString()
            End If
            Return Format(CDbl(StringAmount), "0.00")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "FormatAmount")
            Return "0.00"
        End Try
    End Function

    Public Shared Sub txtReadOnly_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
        Try
            SendKeys.Send("{TAB}")
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", sender.Name & "_txtReadOnly_GotFocus")
        End Try
    End Sub

    Public Shared Sub txtReadOnly_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Try
            If e.KeyCode <> Keys.Tab Then
                e.SuppressKeyPress = True
                SendKeys.Send("{TAB}")
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", sender.Name & "txtReadOnly_KeyDown")
        End Try
    End Sub

    Public Shared Sub SetTextReadOnly(ByRef ReadOnlyTextBox As System.Windows.Forms.TextBox)
        Try
            With ReadOnlyTextBox
                .Enabled = True
                .ReadOnly = False
                .BackColor = Color.FromArgb(236, 233, 216)
                AddHandler .GotFocus, AddressOf txtReadOnly_GotFocus
                AddHandler .KeyDown, AddressOf txtReadOnly_KeyDown
                .ShortcutsEnabled = False
            End With
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetTextReadOnly")
        End Try
    End Sub

    Public Shared Function CheckDecimal(ByVal strValue As String) As String
        'Written By:-(2008/01/21)    'Check decimal value 
        Try
            If strValue <> "" Then
                If strValue.IndexOf(".") > 0 Then
                    If strValue.Length = 3 Then
                        strValue = strValue & "0"
                    Else : strValue = strValue
                    End If
                Else : strValue = strValue & ".00"
                End If
            Else : strValue = "0.00"
            End If
            Return strValue
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetTextReadOnly")
            Return "0.00"
        End Try
    End Function

    Public Shared Function BlankToDecimal(ByVal AmountString As String)
        Try
            If AmountString = "" Then
                Return 0.0
            Else
                Return Format(CType(AmountString, Double), "0.00")
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "BlankToDecimal")
            Return Nothing
        End Try
    End Function

    Public Shared Sub SetTodaysDate(ByRef DatePicker As DateTimePicker)
        Try
            If Now.Date < DatePicker.MinDate Then
                DatePicker.MinDate = Now.Date()
            ElseIf Now.Date > DatePicker.MaxDate Then
                DatePicker.MaxDate = Now.Date()
            Else
                DatePicker.Value = Now.Date()
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", DatePicker.Name & ":SetTodaysDate")
        End Try
    End Sub

    Public Shared Function IsExpired(ByVal ExpDate As Date) As Boolean

        Try
            If DateDiff(DateInterval.Day, Date.Now(), New Date(ExpDate.Year, ExpDate.Month, Date.DaysInMonth(ExpDate.Year, ExpDate.Month))) > 0 Then
                Return True
            Else
                Return False
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "IsExpired")
            Return False
        End Try
    End Function
    Public Shared Function GetDocumentBillItems(ByVal SaleID As Integer, ByVal BillID As String) As DataTable
        Try
            Return DGeneral.GetDocumentBillItems(SaleID, BillID)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "GetDocumentBillItems")
            Return Nothing
        End Try
    End Function
    Public Shared Function GetCustomerDoct(ByVal SaleID As Integer, ByVal BillID As String) As DataTable
        Try
            Return DGeneral.GetCustomerDoct(SaleID, BillID)
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "GetCustomerDoct")
            Return Nothing
        End Try
    End Function
    'Public Shared Function CheckFinalBill(ByVal SaleID As Integer) As String
    '    Try
    '        Return DGeneral.CheckFinalBill(SaleID)
    '    Catch ex As Exception
    '        BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "CheckFinalBill")
    '        Return Nothing
    '    End Try
    'End Function
    Public Shared Function CheckFormMode() As DataTable
        Try
            Return DGeneral.CheckFormMode()
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "CheckFormMode")
            Return Nothing
        End Try
    End Function

    Private Shared Sub SetControlReadOnly(ByRef CntrlToSet As Control)
        Try
            If Not IsNothing(CntrlToSet.Tag) AndAlso CntrlToSet.Tag = "BTN" Then
                For Each btnCtrl As Control In CntrlToSet.Controls
                    If btnCtrl.GetType.Name = "Button" Then
                        If btnCtrl.Tag = "READONLY" Then
                            btnCtrl.Enabled = True
                        Else
                            btnCtrl.Enabled = False
                        End If
                    Else
                        btnCtrl.Enabled = False
                    End If
                Next
                Exit Sub
            ElseIf CntrlToSet.HasChildren Then
                For Each Ctrl As Control In CntrlToSet.Controls
                    SetControlReadOnly(Ctrl)
                Next
            Else
                CntrlToSet.Enabled = False
            End If
        Catch ex As Exception
            BCommon.ErrorHandler(ex.Message, "BAL", "BCommon", "SetControlReadOnly")
        End Try
    End Sub
    Public Shared Sub SetTransationDate(ByRef objDtp As System.Windows.Forms.DateTimePicker)
        If Now.Day = vbSunday Then
            objDtp.Value = Now.AddDays(1)
        Else
            objDtp.Value = Now.Date
        End If
    End Sub
    Public Shared Sub IsColorProduct(ByVal IntProductID As Integer, ByRef blnIsColor As Boolean)
        blnIsColor = System.Convert.ToBoolean(DbHelper.ExecuteScalar("SELECT IsColor FROM PRODUCT WHERE [ID]=" & IntProductID.ToString).ToString())
    End Sub
End Class

